#pragma once
#include <stdint.h>
#include "hiredis/hiredis.h"
#include "RedisResult.h"

class RedisCmdObj;

class RedisConnector 
{
    friend class RedisCmdObj;
public:
    bool        Connect(const char* ip, uint32_t port, const char* password);
    bool        Close();
    redisReply* Execute(const char* format, ...); // binary use "%b"

    bool        AppendCommand(const char* format, ...);
    redisReply* GetReply();

protected:
    bool        _Connect();
    redisReply* _ExecuteVaList(const char* format, va_list ap);

private:
    bool        _AuthPassword();

private:
    uint32_t    m_port;
    char        m_ip[32];
    char*       m_password;
    redisContext*   m_context;

public:
    RedisConnector();
    ~RedisConnector();
};
